using System;
using System.Collections.Generic;
using System.Diagnostics;
using equalidator;
using NUnit.Framework;
using wpffc.contracts.domaindata;
using wpffc.contracts.infrastructure;
using wpffc.flashcardbox.domaindata;

namespace wpffc.flashcardbox.tests
{
    [TestFixture]
    public class test_Get_next_card
    {
        [Test]
        public void Store_flashcardbox()
        {
            var box = new FlashCardBox(0, 1, new int[0]);
            box.Batch.Enqueue(new BatchCard { Card = new Card { Question = "q1" } });

            var sut = new Get_next_card();
            sut.Result += _ => { };
            var fcbStore = new SharedState<IFlashCardBox>();
            sut.Inject(fcbStore);

            sut.Process(box);

            Assert.AreSame(box, fcbStore.Value);
        }


        [Test]
        public void Next_card_is_top_card_on_batch()
        {
            var box = new FlashCardBox(0, 1, new int[0]);
            box.Batch.Enqueue(new BatchCard { Card = new Card { Question = "q1" } });

            var sut = new Get_next_card();
            Card nextCard = null;
            sut.Result += c => { nextCard = c; };
            sut.Inject(new SharedState<IFlashCardBox>());

            sut.Process(box);

            Assert.AreEqual("q1", nextCard.Question);
            Assert.AreEqual(BatchStatus.Full, box.Batch.Status);
        }


        [Test]
        public void Deliver_special_card_on_empty_batch()
        {
            var box = new FlashCardBox(0, 1, new int[0]);

            var sut = new Get_next_card();
            Card endCard = null;
            sut.Result += c => endCard = c;
            sut.Inject(new SharedState<IFlashCardBox>());

            sut.Process(box);

            Equalidator.AreEqual(new Card {Question = "[Congratulations!]", Answer = ""}, endCard);
        }
    }
}